package icu.javacg.storage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import icu.javacg.storage.pojo.Entry;
import icu.javacg.storage.pojo.vo.ReturnResult;
import icu.javacg.storage.service.EntryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/Entry")
@Tag(name = "进入管理接口-刘佩杰")
@CrossOrigin
public class EntryController {

    @Resource
    EntryService entryService;

    @PutMapping("/insert")
    @Operation(summary = "添加信息")
    public ReturnResult<Entry> addEntry(@RequestBody Entry entry){
       return entryService.insertEntry(entry);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除信息")
    public ReturnResult<Boolean> deleteById(@RequestParam Integer id){
         boolean removeById = entryService.removeById(id);
         if (removeById){
             return new ReturnResult<>(3540,"删除成功",removeById);
         }
            return new ReturnResult<>(3040,"删除失败",removeById);
    }

    @GetMapping("/pageList")
    @Operation(summary = "分页查询")
    public Page<Entry> selectPage(int a,int b){
        return entryService.pageList(a,b);
    }
    @GetMapping("/list")
    @Operation(summary = "查询全部信息")
    public ReturnResult<Entry> List(){
         List<Entry> EntryList = entryService.list();
         if (EntryList.size()== 0){
             return new ReturnResult<>(3030,"查询失败");
         }
            return new ReturnResult<>(3540,"查询成功");
    }


    @PostMapping("/update")
    @Operation(summary = "修改进出信息")
    public ReturnResult<Boolean> updateById(@RequestBody Entry entry){
         boolean update = entryService.updateById(entry);
         if (update){
             return new ReturnResult<>(3520,"修改成功",update);
         }
            return new ReturnResult<>(3020,"修改失败",update);
    }
}
